package edu.xidian.bdilab.jrbigdata.Interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @author zhangmin
 * @create 2021-05-13 14:08
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${image.path}")
    private String imagePath;

    // 这个方法是用来配置静态资源的，比如html，js，css，等等
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        /**
         * 访问路径：http://localhost:8888/imagepath/1BOC.png
         * "http://localhost:8888/imagepath/**" 为前端URL访问路径
         * "file:" + imagePath 是本地磁盘映射
         */
        registry.addResourceHandler("/imagepath/**")
                .addResourceLocations("file:" + imagePath);


    }


    // 这个方法用来注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
    @Override
    public void addInterceptors(InterceptorRegistry interceptorRegistry) {
        interceptorRegistry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns()
                .excludePathPatterns("/index.html")
                .excludePathPatterns("/adminLogin.html")
                .excludePathPatterns("/co-register.html")
                .excludePathPatterns("/fi-register.html")
                .excludePathPatterns("/go-register.html")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/imagepath/**")
                .excludePathPatterns("file:"+imagePath+"/**")
                .excludePathPatterns("/government/getNews")
                .excludePathPatterns("/government/getPolicies")
                .excludePathPatterns("/bank/getProductDeal")
                .excludePathPatterns("/bank/dealStatics")
                .excludePathPatterns("/bank/getTopProduct")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/bank/login")
                .excludePathPatterns("/bank/register")
                .excludePathPatterns("/enterprise/register")
                .excludePathPatterns("/enterprise/login")
                .excludePathPatterns("/government/register")
                .excludePathPatterns("/government/login")
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/swagger-ui.html","/swagger-resources/**","/webjars/**","/v2/api-docs/**");
   }


}
